// pages/order/order.js
import Dialog from 'vant-weapp/dialog/dialog';
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: false,
    list: [{}], //买单数据
    list2: [{}], //卖单数据
  },
  alertCancel() {
    wx.showModal({
      title: '温馨提示',
      content: '您确定要撤销订单吗',
      confirmColor: '#BF0F0F',
      cancelText: '再想想',
      success(res) {
        if (res.confirm) {} else if (res.cancel) {}
      }
    })
  },
  // 获取卖单信息
  onChange() {
    var that = this
    wx.request({
      url: app.globalData.baseUrl + '/integral/getIntegralTransactionHistory',
      data: {
        xcxOpenId: app.globalData.xcxOpenId,
        type: 2 //1-买，2-卖
      },
      success(res) {
        var array = res.data.data.rows
        var list = []
        array.forEach((item, index) => {
          var infos = {
            total: item.price * item.num + item.handFee,
            date: item.createTime,
            price: item.price,
            number: item.num
          }
          list.push(infos)
        });
        that.setData({
          list2: list
        })
      }
    })

  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.request({
      url: app.globalData.baseUrl + '/integral/getIntegralTransactionHistory',
      data: {
        xcxOpenId: app.globalData.xcxOpenId,
        type: 1 //1-买，2-卖
      },
      success(res) {
        let data = res.data.data.rows
        let list = that.data.list
        for (let i = 0; i < data.length; i++) {
          list[i].total = data[i].price * data[i].num + data[i].handFee //总价
          list[i].date = data[i].createTime //时间
          list[i].price = data[i].price //单价
          list[i].number = data[i].num //数量
        }
        that.setData({
          list
        })
      }
    })
  }
})